<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/15/0015
 * Time: 15:18
 */

namespace app\sports_admin\model;


use think\Model;
use traits\model\SoftDelete;

class Grade extends Model
{
    use SoftDelete;
    protected $table = 'grade';

    protected $pk = 'id';

    protected $autoWriteTimestamp = true;


    /**
     * 获取年级列表
     * @param $page 第几页
     * @param $rows 每页显示的条数
     * @param $sort 要排序的字段
     * @param $sortOrder 升序/降序
     */
    public static function gradeList($page,$rows,$sort,$sortOrder)
    {
        $result = self::order("{$sort}","{$sortOrder}")->limit($rows)->page($page)->select();
        $count = self::count();
        return json(['total'=>$count,'rows'=>$result]);
    }
    /*
     * 查询年级是否存在
     * @param $grade
     */
    public static function findGrade($grade)
    {
        return self::where('grade_title',$grade)->find();
    }
    /*
     * 添加学生信息
     * @param array $input 年级信息
     */
    public static function insertGradeInfo($input)
    {
        return self::create(['grade_title'=>$input['grade'],'type'=>$input['type'],'grade_name'=>$input['grade_name']]);
    }
}